package com.example.yuejian21.nongfusanquan.yuejian21.fragment;

import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Toast;

import com.example.yuejian21.nongfusanquan.yuejian21.R;
import com.example.yuejian21.nongfusanquan.yuejian21.adapter.ClubAdapter;
import com.example.yuejian21.nongfusanquan.yuejian21.base.RetrofitListener;
import com.example.yuejian21.nongfusanquan.yuejian21.javabean.Clubbean;
import com.example.yuejian21.nongfusanquan.yuejian21.model.Clubmodel;

import java.util.List;

/**
 * Created by Nongfusanquan on 2017-10-10.
 */

public class ClubFragment extends Fragment implements RetrofitListener<List<Clubbean>> {
    private RecyclerView recyclerView;
    private View view;
    private String cid;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container,
                             Bundle savedInstanceState)
    {
        view= inflater.inflate(R.layout.fragment_club, container, false);
        initViews();
        getData();
        return view;
    }


    private void initViews(){

        recyclerView=(RecyclerView)view.findViewById(R.id.rv);
        recyclerView.setLayoutManager(new LinearLayoutManager(this.getActivity()));//设置布局
    }
    void getData(){
        Clubmodel showModel=new Clubmodel();
        showModel.getClublist(this);
    }


    @Override
    public void onSuccess(List<Clubbean> data) {
        recyclerView.setAdapter(new ClubAdapter(ClubFragment.this.getActivity(),data));
    }

    @Override
    public void onFail() { Toast.makeText(getActivity(), "网络发生错误", Toast.LENGTH_SHORT).show();

    }

}